﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using InvoiceChecking.Entities;
using InvoiceChecking.Data;

#endregion

namespace InvoiceChecking.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="SunInvoiceProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class SunInvoiceProviderBaseCore : EntityViewProviderBase<SunInvoice>
	{
		#region Custom Methods
		
		
		#region _SunInvoice_InvoiceDetails
		
		/// <summary>
		///	This method wrap the '_SunInvoice_InvoiceDetails' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet InvoiceDetails(System.Int32? allocRef)
		{
			return InvoiceDetails(null, 0, int.MaxValue , allocRef);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_InvoiceDetails' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet InvoiceDetails(int start, int pageLength, System.Int32? allocRef)
		{
			return InvoiceDetails(null, start, pageLength , allocRef);
		}
				
		/// <summary>
		///	This method wrap the '_SunInvoice_InvoiceDetails' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet InvoiceDetails(TransactionManager transactionManager, System.Int32? allocRef)
		{
			return InvoiceDetails(transactionManager, 0, int.MaxValue , allocRef);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_InvoiceDetails' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet InvoiceDetails(TransactionManager transactionManager, int start, int pageLength, System.Int32? allocRef);
		
		#endregion

		
		#region _SunInvoice_Invoice
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Invoice' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Invoice(System.Int32? jrnalNo, System.Int32? allocRef)
		{
			 Invoice(null, 0, int.MaxValue , jrnalNo, allocRef);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Invoice' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Invoice(int start, int pageLength, System.Int32? jrnalNo, System.Int32? allocRef)
		{
			 Invoice(null, start, pageLength , jrnalNo, allocRef);
		}
				
		/// <summary>
		///	This method wrap the '_SunInvoice_Invoice' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void Invoice(TransactionManager transactionManager, System.Int32? jrnalNo, System.Int32? allocRef)
		{
			 Invoice(transactionManager, 0, int.MaxValue , jrnalNo, allocRef);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Invoice' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void Invoice(TransactionManager transactionManager, int start, int pageLength, System.Int32? jrnalNo, System.Int32? allocRef);
		
		#endregion

		
		#region _SunInvoice_JR
		
		/// <summary>
		///	This method wrap the '_SunInvoice_JR' stored procedure. 
		/// </summary>
		/// <param name="period"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet JR(System.Int32? period)
		{
			return JR(null, 0, int.MaxValue , period);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_JR' stored procedure. 
		/// </summary>
		/// <param name="period"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet JR(int start, int pageLength, System.Int32? period)
		{
			return JR(null, start, pageLength , period);
		}
				
		/// <summary>
		///	This method wrap the '_SunInvoice_JR' stored procedure. 
		/// </summary>
		/// <param name="period"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet JR(TransactionManager transactionManager, System.Int32? period)
		{
			return JR(transactionManager, 0, int.MaxValue , period);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_JR' stored procedure. 
		/// </summary>
		/// <param name="period"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet JR(TransactionManager transactionManager, int start, int pageLength, System.Int32? period);
		
		#endregion

		
		#region _SunInvoice_GetCreditCard
		
		/// <summary>
		///	This method wrap the '_SunInvoice_GetCreditCard' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="creditCardId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetCreditCard(System.Int32? allocRef, System.Int32? creditCardId)
		{
			return GetCreditCard(null, 0, int.MaxValue , allocRef, creditCardId);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_GetCreditCard' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="creditCardId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetCreditCard(int start, int pageLength, System.Int32? allocRef, System.Int32? creditCardId)
		{
			return GetCreditCard(null, start, pageLength , allocRef, creditCardId);
		}
				
		/// <summary>
		///	This method wrap the '_SunInvoice_GetCreditCard' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="creditCardId"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet GetCreditCard(TransactionManager transactionManager, System.Int32? allocRef, System.Int32? creditCardId)
		{
			return GetCreditCard(transactionManager, 0, int.MaxValue , allocRef, creditCardId);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_GetCreditCard' stored procedure. 
		/// </summary>
		/// <param name="allocRef"> A <c>System.Int32?</c> instance.</param>
		/// <param name="creditCardId"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet GetCreditCard(TransactionManager transactionManager, int start, int pageLength, System.Int32? allocRef, System.Int32? creditCardId);
		
		#endregion

		
		#region _SunInvoice_Journal
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Journal' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Journal(System.Int32? jrnalNo)
		{
			return Journal(null, 0, int.MaxValue , jrnalNo);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Journal' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Journal(int start, int pageLength, System.Int32? jrnalNo)
		{
			return Journal(null, start, pageLength , jrnalNo);
		}
				
		/// <summary>
		///	This method wrap the '_SunInvoice_Journal' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public DataSet Journal(TransactionManager transactionManager, System.Int32? jrnalNo)
		{
			return Journal(transactionManager, 0, int.MaxValue , jrnalNo);
		}
		
		/// <summary>
		///	This method wrap the '_SunInvoice_Journal' stored procedure. 
		/// </summary>
		/// <param name="jrnalNo"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="DataSet"/> instance.</returns>
		public abstract DataSet Journal(TransactionManager transactionManager, int start, int pageLength, System.Int32? jrnalNo);
		
		#endregion

		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;SunInvoice&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;SunInvoice&gt;"/></returns>
		protected static VList&lt;SunInvoice&gt; Fill(DataSet dataSet, VList<SunInvoice> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<SunInvoice>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;SunInvoice&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<SunInvoice>"/></returns>
		protected static VList&lt;SunInvoice&gt; Fill(DataTable dataTable, VList<SunInvoice> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					SunInvoice c = new SunInvoice();
					c.AccntCode = (Convert.IsDBNull(row["ACCNT_CODE"]))?string.Empty:(System.String)row["ACCNT_CODE"];
					c.TransDate = (Convert.IsDBNull(row["TRANS_DATE"]))?(int)0:(System.Int32)row["TRANS_DATE"];
					c.Period = (Convert.IsDBNull(row["PERIOD"]))?(int)0:(System.Int32)row["PERIOD"];
					c.JrnalNo = (Convert.IsDBNull(row["JRNAL_NO"]))?(int)0:(System.Int32)row["JRNAL_NO"];
					c.JrnalLine = (Convert.IsDBNull(row["JRNAL_LINE"]))?(int)0:(System.Int32)row["JRNAL_LINE"];
					c.Treference = (Convert.IsDBNull(row["TREFERENCE"]))?string.Empty:(System.String)row["TREFERENCE"];
					c.Amount = (Convert.IsDBNull(row["AMOUNT"]))?0.0m:(System.Decimal)row["AMOUNT"];
					c.DC = (Convert.IsDBNull(row["D_C"]))?string.Empty:(System.String)row["D_C"];
					c.Descriptn = (Convert.IsDBNull(row["DESCRIPTN"]))?string.Empty:(System.String)row["DESCRIPTN"];
					c.ConvRate = (Convert.IsDBNull(row["CONV_RATE"]))?0.0m:(System.Decimal)row["CONV_RATE"];
					c.OtherAmt = (Convert.IsDBNull(row["OTHER_AMT"]))?0.0m:(System.Decimal)row["OTHER_AMT"];
					c.AnalT0 = (Convert.IsDBNull(row["ANAL_T0"]))?string.Empty:(System.String)row["ANAL_T0"];
					c.AnalT1 = (Convert.IsDBNull(row["ANAL_T1"]))?string.Empty:(System.String)row["ANAL_T1"];
					c.AnalT2 = (Convert.IsDBNull(row["ANAL_T2"]))?string.Empty:(System.String)row["ANAL_T2"];
					c.AnalT3 = (Convert.IsDBNull(row["ANAL_T3"]))?string.Empty:(System.String)row["ANAL_T3"];
					c.AnalT4 = (Convert.IsDBNull(row["ANAL_T4"]))?string.Empty:(System.String)row["ANAL_T4"];
					c.AnalT5 = (Convert.IsDBNull(row["ANAL_T5"]))?string.Empty:(System.String)row["ANAL_T5"];
					c.AllocRef = (Convert.IsDBNull(row["ALLOC_REF"]))?(int)0:(System.Int32)row["ALLOC_REF"];
					c.SunRefer = (Convert.IsDBNull(row["SunRefer"]))?string.Empty:(System.String)row["SunRefer"];
					c.JrnalSrce = (Convert.IsDBNull(row["JRNAL_SRCE"]))?string.Empty:(System.String)row["JRNAL_SRCE"];
					c.Description = (Convert.IsDBNull(row["Description"]))?string.Empty:(System.String)row["Description"];
					c.UserPrinted = (Convert.IsDBNull(row["UserPrinted"]))?string.Empty:(System.String)row["UserPrinted"];
					c.DatePrinted = (Convert.IsDBNull(row["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)row["DatePrinted"];
					c.CreditCardId = (Convert.IsDBNull(row["CreditCardId"]))?(int)0:(System.Int32?)row["CreditCardId"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;SunInvoice&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;SunInvoice&gt;"/></returns>
		protected VList<SunInvoice> Fill(IDataReader reader, VList<SunInvoice> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					SunInvoice entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<SunInvoice>("SunInvoice",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new SunInvoice();
					}
					
					entity.SuppressEntityEvents = true;

					entity.AccntCode = (System.String)reader[((int)SunInvoiceColumn.AccntCode)];
					//entity.AccntCode = (Convert.IsDBNull(reader["ACCNT_CODE"]))?string.Empty:(System.String)reader["ACCNT_CODE"];
					entity.TransDate = (System.Int32)reader[((int)SunInvoiceColumn.TransDate)];
					//entity.TransDate = (Convert.IsDBNull(reader["TRANS_DATE"]))?(int)0:(System.Int32)reader["TRANS_DATE"];
					entity.Period = (System.Int32)reader[((int)SunInvoiceColumn.Period)];
					//entity.Period = (Convert.IsDBNull(reader["PERIOD"]))?(int)0:(System.Int32)reader["PERIOD"];
					entity.JrnalNo = (System.Int32)reader[((int)SunInvoiceColumn.JrnalNo)];
					//entity.JrnalNo = (Convert.IsDBNull(reader["JRNAL_NO"]))?(int)0:(System.Int32)reader["JRNAL_NO"];
					entity.JrnalLine = (System.Int32)reader[((int)SunInvoiceColumn.JrnalLine)];
					//entity.JrnalLine = (Convert.IsDBNull(reader["JRNAL_LINE"]))?(int)0:(System.Int32)reader["JRNAL_LINE"];
					entity.Treference = (System.String)reader[((int)SunInvoiceColumn.Treference)];
					//entity.Treference = (Convert.IsDBNull(reader["TREFERENCE"]))?string.Empty:(System.String)reader["TREFERENCE"];
					entity.Amount = (System.Decimal)reader[((int)SunInvoiceColumn.Amount)];
					//entity.Amount = (Convert.IsDBNull(reader["AMOUNT"]))?0.0m:(System.Decimal)reader["AMOUNT"];
					entity.DC = (System.String)reader[((int)SunInvoiceColumn.DC)];
					//entity.DC = (Convert.IsDBNull(reader["D_C"]))?string.Empty:(System.String)reader["D_C"];
					entity.Descriptn = (System.String)reader[((int)SunInvoiceColumn.Descriptn)];
					//entity.Descriptn = (Convert.IsDBNull(reader["DESCRIPTN"]))?string.Empty:(System.String)reader["DESCRIPTN"];
					entity.ConvRate = (System.Decimal)reader[((int)SunInvoiceColumn.ConvRate)];
					//entity.ConvRate = (Convert.IsDBNull(reader["CONV_RATE"]))?0.0m:(System.Decimal)reader["CONV_RATE"];
					entity.OtherAmt = (System.Decimal)reader[((int)SunInvoiceColumn.OtherAmt)];
					//entity.OtherAmt = (Convert.IsDBNull(reader["OTHER_AMT"]))?0.0m:(System.Decimal)reader["OTHER_AMT"];
					entity.AnalT0 = (System.String)reader[((int)SunInvoiceColumn.AnalT0)];
					//entity.AnalT0 = (Convert.IsDBNull(reader["ANAL_T0"]))?string.Empty:(System.String)reader["ANAL_T0"];
					entity.AnalT1 = (System.String)reader[((int)SunInvoiceColumn.AnalT1)];
					//entity.AnalT1 = (Convert.IsDBNull(reader["ANAL_T1"]))?string.Empty:(System.String)reader["ANAL_T1"];
					entity.AnalT2 = (System.String)reader[((int)SunInvoiceColumn.AnalT2)];
					//entity.AnalT2 = (Convert.IsDBNull(reader["ANAL_T2"]))?string.Empty:(System.String)reader["ANAL_T2"];
					entity.AnalT3 = (System.String)reader[((int)SunInvoiceColumn.AnalT3)];
					//entity.AnalT3 = (Convert.IsDBNull(reader["ANAL_T3"]))?string.Empty:(System.String)reader["ANAL_T3"];
					entity.AnalT4 = (System.String)reader[((int)SunInvoiceColumn.AnalT4)];
					//entity.AnalT4 = (Convert.IsDBNull(reader["ANAL_T4"]))?string.Empty:(System.String)reader["ANAL_T4"];
					entity.AnalT5 = (System.String)reader[((int)SunInvoiceColumn.AnalT5)];
					//entity.AnalT5 = (Convert.IsDBNull(reader["ANAL_T5"]))?string.Empty:(System.String)reader["ANAL_T5"];
					entity.AllocRef = (System.Int32)reader[((int)SunInvoiceColumn.AllocRef)];
					//entity.AllocRef = (Convert.IsDBNull(reader["ALLOC_REF"]))?(int)0:(System.Int32)reader["ALLOC_REF"];
					entity.SunRefer = (reader.IsDBNull(((int)SunInvoiceColumn.SunRefer)))?null:(System.String)reader[((int)SunInvoiceColumn.SunRefer)];
					//entity.SunRefer = (Convert.IsDBNull(reader["SunRefer"]))?string.Empty:(System.String)reader["SunRefer"];
					entity.JrnalSrce = (System.String)reader[((int)SunInvoiceColumn.JrnalSrce)];
					//entity.JrnalSrce = (Convert.IsDBNull(reader["JRNAL_SRCE"]))?string.Empty:(System.String)reader["JRNAL_SRCE"];
					entity.Description = (reader.IsDBNull(((int)SunInvoiceColumn.Description)))?null:(System.String)reader[((int)SunInvoiceColumn.Description)];
					//entity.Description = (Convert.IsDBNull(reader["Description"]))?string.Empty:(System.String)reader["Description"];
					entity.UserPrinted = (reader.IsDBNull(((int)SunInvoiceColumn.UserPrinted)))?null:(System.String)reader[((int)SunInvoiceColumn.UserPrinted)];
					//entity.UserPrinted = (Convert.IsDBNull(reader["UserPrinted"]))?string.Empty:(System.String)reader["UserPrinted"];
					entity.DatePrinted = (reader.IsDBNull(((int)SunInvoiceColumn.DatePrinted)))?null:(System.DateTime?)reader[((int)SunInvoiceColumn.DatePrinted)];
					//entity.DatePrinted = (Convert.IsDBNull(reader["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)reader["DatePrinted"];
					entity.CreditCardId = (reader.IsDBNull(((int)SunInvoiceColumn.CreditCardId)))?null:(System.Int32?)reader[((int)SunInvoiceColumn.CreditCardId)];
					//entity.CreditCardId = (Convert.IsDBNull(reader["CreditCardId"]))?(int)0:(System.Int32?)reader["CreditCardId"];
					entity.AcceptChanges();
					entity.SuppressEntityEvents = false;
					
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="SunInvoice"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="SunInvoice"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, SunInvoice entity)
		{
			reader.Read();
			entity.AccntCode = (System.String)reader[((int)SunInvoiceColumn.AccntCode)];
			//entity.AccntCode = (Convert.IsDBNull(reader["ACCNT_CODE"]))?string.Empty:(System.String)reader["ACCNT_CODE"];
			entity.TransDate = (System.Int32)reader[((int)SunInvoiceColumn.TransDate)];
			//entity.TransDate = (Convert.IsDBNull(reader["TRANS_DATE"]))?(int)0:(System.Int32)reader["TRANS_DATE"];
			entity.Period = (System.Int32)reader[((int)SunInvoiceColumn.Period)];
			//entity.Period = (Convert.IsDBNull(reader["PERIOD"]))?(int)0:(System.Int32)reader["PERIOD"];
			entity.JrnalNo = (System.Int32)reader[((int)SunInvoiceColumn.JrnalNo)];
			//entity.JrnalNo = (Convert.IsDBNull(reader["JRNAL_NO"]))?(int)0:(System.Int32)reader["JRNAL_NO"];
			entity.JrnalLine = (System.Int32)reader[((int)SunInvoiceColumn.JrnalLine)];
			//entity.JrnalLine = (Convert.IsDBNull(reader["JRNAL_LINE"]))?(int)0:(System.Int32)reader["JRNAL_LINE"];
			entity.Treference = (System.String)reader[((int)SunInvoiceColumn.Treference)];
			//entity.Treference = (Convert.IsDBNull(reader["TREFERENCE"]))?string.Empty:(System.String)reader["TREFERENCE"];
			entity.Amount = (System.Decimal)reader[((int)SunInvoiceColumn.Amount)];
			//entity.Amount = (Convert.IsDBNull(reader["AMOUNT"]))?0.0m:(System.Decimal)reader["AMOUNT"];
			entity.DC = (System.String)reader[((int)SunInvoiceColumn.DC)];
			//entity.DC = (Convert.IsDBNull(reader["D_C"]))?string.Empty:(System.String)reader["D_C"];
			entity.Descriptn = (System.String)reader[((int)SunInvoiceColumn.Descriptn)];
			//entity.Descriptn = (Convert.IsDBNull(reader["DESCRIPTN"]))?string.Empty:(System.String)reader["DESCRIPTN"];
			entity.ConvRate = (System.Decimal)reader[((int)SunInvoiceColumn.ConvRate)];
			//entity.ConvRate = (Convert.IsDBNull(reader["CONV_RATE"]))?0.0m:(System.Decimal)reader["CONV_RATE"];
			entity.OtherAmt = (System.Decimal)reader[((int)SunInvoiceColumn.OtherAmt)];
			//entity.OtherAmt = (Convert.IsDBNull(reader["OTHER_AMT"]))?0.0m:(System.Decimal)reader["OTHER_AMT"];
			entity.AnalT0 = (System.String)reader[((int)SunInvoiceColumn.AnalT0)];
			//entity.AnalT0 = (Convert.IsDBNull(reader["ANAL_T0"]))?string.Empty:(System.String)reader["ANAL_T0"];
			entity.AnalT1 = (System.String)reader[((int)SunInvoiceColumn.AnalT1)];
			//entity.AnalT1 = (Convert.IsDBNull(reader["ANAL_T1"]))?string.Empty:(System.String)reader["ANAL_T1"];
			entity.AnalT2 = (System.String)reader[((int)SunInvoiceColumn.AnalT2)];
			//entity.AnalT2 = (Convert.IsDBNull(reader["ANAL_T2"]))?string.Empty:(System.String)reader["ANAL_T2"];
			entity.AnalT3 = (System.String)reader[((int)SunInvoiceColumn.AnalT3)];
			//entity.AnalT3 = (Convert.IsDBNull(reader["ANAL_T3"]))?string.Empty:(System.String)reader["ANAL_T3"];
			entity.AnalT4 = (System.String)reader[((int)SunInvoiceColumn.AnalT4)];
			//entity.AnalT4 = (Convert.IsDBNull(reader["ANAL_T4"]))?string.Empty:(System.String)reader["ANAL_T4"];
			entity.AnalT5 = (System.String)reader[((int)SunInvoiceColumn.AnalT5)];
			//entity.AnalT5 = (Convert.IsDBNull(reader["ANAL_T5"]))?string.Empty:(System.String)reader["ANAL_T5"];
			entity.AllocRef = (System.Int32)reader[((int)SunInvoiceColumn.AllocRef)];
			//entity.AllocRef = (Convert.IsDBNull(reader["ALLOC_REF"]))?(int)0:(System.Int32)reader["ALLOC_REF"];
			entity.SunRefer = (reader.IsDBNull(((int)SunInvoiceColumn.SunRefer)))?null:(System.String)reader[((int)SunInvoiceColumn.SunRefer)];
			//entity.SunRefer = (Convert.IsDBNull(reader["SunRefer"]))?string.Empty:(System.String)reader["SunRefer"];
			entity.JrnalSrce = (System.String)reader[((int)SunInvoiceColumn.JrnalSrce)];
			//entity.JrnalSrce = (Convert.IsDBNull(reader["JRNAL_SRCE"]))?string.Empty:(System.String)reader["JRNAL_SRCE"];
			entity.Description = (reader.IsDBNull(((int)SunInvoiceColumn.Description)))?null:(System.String)reader[((int)SunInvoiceColumn.Description)];
			//entity.Description = (Convert.IsDBNull(reader["Description"]))?string.Empty:(System.String)reader["Description"];
			entity.UserPrinted = (reader.IsDBNull(((int)SunInvoiceColumn.UserPrinted)))?null:(System.String)reader[((int)SunInvoiceColumn.UserPrinted)];
			//entity.UserPrinted = (Convert.IsDBNull(reader["UserPrinted"]))?string.Empty:(System.String)reader["UserPrinted"];
			entity.DatePrinted = (reader.IsDBNull(((int)SunInvoiceColumn.DatePrinted)))?null:(System.DateTime?)reader[((int)SunInvoiceColumn.DatePrinted)];
			//entity.DatePrinted = (Convert.IsDBNull(reader["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)reader["DatePrinted"];
			entity.CreditCardId = (reader.IsDBNull(((int)SunInvoiceColumn.CreditCardId)))?null:(System.Int32?)reader[((int)SunInvoiceColumn.CreditCardId)];
			//entity.CreditCardId = (Convert.IsDBNull(reader["CreditCardId"]))?(int)0:(System.Int32?)reader["CreditCardId"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="SunInvoice"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="SunInvoice"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, SunInvoice entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.AccntCode = (Convert.IsDBNull(dataRow["ACCNT_CODE"]))?string.Empty:(System.String)dataRow["ACCNT_CODE"];
			entity.TransDate = (Convert.IsDBNull(dataRow["TRANS_DATE"]))?(int)0:(System.Int32)dataRow["TRANS_DATE"];
			entity.Period = (Convert.IsDBNull(dataRow["PERIOD"]))?(int)0:(System.Int32)dataRow["PERIOD"];
			entity.JrnalNo = (Convert.IsDBNull(dataRow["JRNAL_NO"]))?(int)0:(System.Int32)dataRow["JRNAL_NO"];
			entity.JrnalLine = (Convert.IsDBNull(dataRow["JRNAL_LINE"]))?(int)0:(System.Int32)dataRow["JRNAL_LINE"];
			entity.Treference = (Convert.IsDBNull(dataRow["TREFERENCE"]))?string.Empty:(System.String)dataRow["TREFERENCE"];
			entity.Amount = (Convert.IsDBNull(dataRow["AMOUNT"]))?0.0m:(System.Decimal)dataRow["AMOUNT"];
			entity.DC = (Convert.IsDBNull(dataRow["D_C"]))?string.Empty:(System.String)dataRow["D_C"];
			entity.Descriptn = (Convert.IsDBNull(dataRow["DESCRIPTN"]))?string.Empty:(System.String)dataRow["DESCRIPTN"];
			entity.ConvRate = (Convert.IsDBNull(dataRow["CONV_RATE"]))?0.0m:(System.Decimal)dataRow["CONV_RATE"];
			entity.OtherAmt = (Convert.IsDBNull(dataRow["OTHER_AMT"]))?0.0m:(System.Decimal)dataRow["OTHER_AMT"];
			entity.AnalT0 = (Convert.IsDBNull(dataRow["ANAL_T0"]))?string.Empty:(System.String)dataRow["ANAL_T0"];
			entity.AnalT1 = (Convert.IsDBNull(dataRow["ANAL_T1"]))?string.Empty:(System.String)dataRow["ANAL_T1"];
			entity.AnalT2 = (Convert.IsDBNull(dataRow["ANAL_T2"]))?string.Empty:(System.String)dataRow["ANAL_T2"];
			entity.AnalT3 = (Convert.IsDBNull(dataRow["ANAL_T3"]))?string.Empty:(System.String)dataRow["ANAL_T3"];
			entity.AnalT4 = (Convert.IsDBNull(dataRow["ANAL_T4"]))?string.Empty:(System.String)dataRow["ANAL_T4"];
			entity.AnalT5 = (Convert.IsDBNull(dataRow["ANAL_T5"]))?string.Empty:(System.String)dataRow["ANAL_T5"];
			entity.AllocRef = (Convert.IsDBNull(dataRow["ALLOC_REF"]))?(int)0:(System.Int32)dataRow["ALLOC_REF"];
			entity.SunRefer = (Convert.IsDBNull(dataRow["SunRefer"]))?string.Empty:(System.String)dataRow["SunRefer"];
			entity.JrnalSrce = (Convert.IsDBNull(dataRow["JRNAL_SRCE"]))?string.Empty:(System.String)dataRow["JRNAL_SRCE"];
			entity.Description = (Convert.IsDBNull(dataRow["Description"]))?string.Empty:(System.String)dataRow["Description"];
			entity.UserPrinted = (Convert.IsDBNull(dataRow["UserPrinted"]))?string.Empty:(System.String)dataRow["UserPrinted"];
			entity.DatePrinted = (Convert.IsDBNull(dataRow["DatePrinted"]))?DateTime.MinValue:(System.DateTime?)dataRow["DatePrinted"];
			entity.CreditCardId = (Convert.IsDBNull(dataRow["CreditCardId"]))?(int)0:(System.Int32?)dataRow["CreditCardId"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region SunInvoiceFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunInvoice"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SunInvoiceFilterBuilder : SqlFilterBuilder<SunInvoiceColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunInvoiceFilterBuilder class.
		/// </summary>
		public SunInvoiceFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SunInvoiceFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SunInvoiceFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SunInvoiceFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SunInvoiceFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SunInvoiceFilterBuilder

	#region SunInvoiceParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunInvoice"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class SunInvoiceParameterBuilder : ParameterizedSqlFilterBuilder<SunInvoiceColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunInvoiceParameterBuilder class.
		/// </summary>
		public SunInvoiceParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the SunInvoiceParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public SunInvoiceParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the SunInvoiceParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public SunInvoiceParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion SunInvoiceParameterBuilder
	
	#region SunInvoiceSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="SunInvoice"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class SunInvoiceSortBuilder : SqlSortBuilder<SunInvoiceColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the SunInvoiceSqlSortBuilder class.
		/// </summary>
		public SunInvoiceSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion SunInvoiceSortBuilder

} // end namespace
